

function SubmitRow($scope, line, callback){
    var row = line;
    if(line['O']="" && $scope.category=="常规装置"){
        alert("请填写必要的内容");
        return;
    }
    if(line['producer']="" || line['industry']==""){
        alert("请填写必要的内容");
        return;
    }

    // for(var key in $scope.Addrs){
    //     var addr = $scope.Addrs[key];
    //     if(key=="address"){     //// 内置字段
    //         row['province'] = addr.selProvince;
    //         row['city'] = addr.selCity;
    //         row['county'] = addr.selCounty;
    //         row[key] = row[key+"_detail"];
    //     }else{
    //         row[key] = addr.selProvince + " " + addr.selCity + " " + addr.selCounty 
    //             + "" + row[key+"_detail"];
    //     }
    // }
    if($scope.selected.value.id==-1){
        alert("请选择公司，如不存在可创建新公司！");
        return;
    }
    line['companyId'] = $scope.selected.value.id;
    line['category'] = $scope.category;
    cout(row);

    var data = angular.toJson(row); 
    ajaxData("add_device", {row:data}, function(dt){
        if(callback)callback(dt);

    });
};

function collectRow($scope, item){
	var row = {};
    for(var col in item){
        row[col] = item[col];
        if(col in $scope.Addrs){
            var ps =  [item["province"], item["city"], item["county"]];
            row[col+"_detail"] = item[col];
            //// 内置地址字段对应三个子字段，自定义则无
            if(col!="address"){
                ps = (item[col] + "    ").split(" ");
                row[col+"_detail"] = ps.slice(3).join("");
            }
            $scope.Addrs[col]["selProvince"] = ps[0];
            $scope.Addrs[col]["selCity"] = ps[1];
            $scope.Addrs[col]["selCounty"] = ps[2];
        }
    }
    return row;
}
function copyObject(obj){
    var d = {};
    for(var k in obj)d[k] = obj[k];
    return d;
}
function changeType(category, cols, line){
    var keys = {
        "O":"氧", "N":"氮", "Ar":"氩", "LO":"液氧", "LN":"液氮", "LAr":"液氩"
    }
    var Categorys = {
        "常规装置":["O", "N", "Ar"], "高纯装置":["O", "N"], "液体装置":["LO", "LN", "LAr"]
    };
    var cache = {};
    cols.forEach(function(c, i){
        if(c.field in keys){
            c.enable = false;
            line[c.field] = '';
            cache[c.field] = i;
        }
    });
    Categorys[category].forEach(function(k){
        cols[cache[k]].enable = true;
    });
}


function getEditDeviceTpl(){
	/*
	<form class="form-horizontal" role="form">
        <div class="col-sm-2"></div>
        <div class="col-sm-10" style="text-align: left; margin-bottom:35px; ">
            <label class="radio-inline" ng-repeat="cls in Categorys" style="font-weight:700;margin-left:30px">
                <input type="radio" ng-model="category" ng-value="cls" ng-click="changeType(cls)" name="category" >{{cls}}
            </label>
        </div>

        <div class="form-group" style="margin-bottom:30px">
            <label class="col-sm-2 control-label">公司名称</label>
            <div class="col-sm-6">
                <ui-select ng-model="selected.value" ng-blur="selChange()" ng-change="selChange()">
                    <ui-select-match>
                        <span ng-bind="$select.selected.name"></span>
                    </ui-select-match>
                    <ui-select-choices repeat="item in (cplist | filter: $select.search) track by item.id">
                        <span ng-bind="item.name"></span>
                    </ui-select-choices>
                </ui-select>
            </div>
            <div class="col-sm-2" style="padding-top:12px; text-algin:center ">
                <span class="label label-info pointer" ng-click="createCompany()" 
                style="font-size:14px;font-weight:400;padding:5px 10px">创建新公司</span>
            </div>
            <div class="col-sm-2" style="padding-top:5px;font-size:16px; ">
               *
            </div>
        </div>

        <div class="form-group" ng-repeat="row in rows" ng-show="row.enable" on-finish-render-filters>
            <label class="col-sm-2 control-label">{{row.name}}</label>
            <div class="col-sm-8" ng-switch="row.type">
                <div ng-switch-when="text">
                    <input ng-model="item[row.field]" type="text" class="form-control" placeholder="{{row.describe}}">
                </div>
                <!-- 单选按钮 -->
                <div ng-switch-when="radio">
                    <label class="radio-inline" ng-repeat="sel in selOptions[row.field]">
                        <input type="radio" ng-model="item[row.field]" ng-value="sel.name" name="{{row.field}}_r" >{{sel.name}}
                    </label>
                </div>
                <!-- 下拉列表 -->
                <div ng-switch-when="select">
                    <select class="form-control" ng-model='item[row.field]' ng-options="x.name as x.name for x in selOptions[row.field]"></select>
                </div>
                <!-- 时间选择框 -->
                <div ng-switch-when="time">
                    <div class="input-group date" data-date-format="yyyy-mm-dd" style="margin-top:4px">
                    <input class="form-control" size="14" type="text" ng-model="item[row.field]" style="height: 30px; width:150px">
                    <span class="input-group-addon bg-light btn-sm f" >
                        <span class="glyphicon glyphicon glyphicon-time" style="font-size: 10px"></span>
                    </span>
                    </div>  
                </div>
                <!--地址选择组件-->
                <div ng-switch-when="address" style="margin-top: 3px">
                    <div class="input-group" style="margin-bottom:8px">
                    <select ng-model="Addrs[row.field].selProvince" style="width:120px; float:left" ng-change="selectChina(0, row.field);"
                            ng-options="x for x in Addrs[row.field].libs.provinces"></select>
                    <select ng-model="Addrs[row.field].selCity" style="width:120px; float:left" ng-change="selectChina(1, row.field);"
                            ng-options="x for x in Addrs[row.field].libs.citys"></select>
                    <select ng-model="Addrs[row.field].selCounty" style="width:120px; float:left"
                            ng-options="x for x in Addrs[row.field].libs.countys"></select>
                    </div>
                    <div class="input-group">
                        <span class="input-group-btn">
                            <input type="text" class="form-control info" style="width:240px" 
                            value="{{Addrs[row.field].selProvince}} {{Addrs[row.field].selCity}} {{Addrs[row.field].selCounty}}"
                             disabled>
                        </span>
                        <input type="text" ng-model="item[row.field+'_detail']" class="form-control" placeholder="街道、乡镇">
                    </div>
                </div>
            </div>
            <!-- End middle col -->
            <label class="col-sm-2" ng-show="row.notNull"> *</label>
        </div>
        <div class="col-sm-2"></div>
        <div class="col-sm-8 pb15" align="center" style="margin-top:10px">
            <button type="button" class="btn btn-default" ng-click="clear()">清空</button>
            <button type="button" class="btn btn-primary" ng-click="Submit()">提交</button>
        </div>
    </form>
	*/
}